import { createApp } from "vue";
import { createPinia } from "pinia";
import App from "./App.vue";
import router from "./router";
import { throttle } from "@/ts/throttle";
import { debounce } from "@/ts/debounce";

// import { registerMicroApps, start } from "qiankun";

// import { qiankunWindow, renderWithQiankun } from "vite-plugin-qiankun";
// console.log("qiankunWindow", qiankunWindow);

// if (!qiankunWindow.__POWERED_BY_QIANKUN__) {
//   render();
// }

// renderWithQiankun({
//   bootstrap: () => {
//     console.log("[vue] vue app bootstraped");
//   },
//   mount: (props: QiankunProps) => {
//     console.log("[vue] props from main framework", props);
//     render(props);
//   },
//   unmount: (props: QiankunProps) => {
//     window.console.log("unmount", props);
//     app.unmount();
//   },
//   update: (props: QiankunProps) => {
//     window.console.log("update");
//   },
// });

const pinia = createPinia();

const app = createApp(App);
// 将防抖和节流函数挂载到Vue实例的原型上，以便在组件中可以通过this访问
app.config.globalProperties.$debounce = debounce;
app.config.globalProperties.$throttle = throttle;
app.config.globalProperties.$globalFunc = () => {
  console.log("test globalFunc 全局函数");
};

console.log("process.env.NODE_ENV-----", process.env.NODE_ENV);
const apiBaseUrl = import.meta.env.VITE_APP_ENV;
console.log("import.meta.env.VITE_APP_ENV-----", apiBaseUrl);

app.use(pinia);
app.use(router);
app.mount("#app");

// 主应用配置
// registerMicroApps([
//   {
//     name: "silvia micro app", // app name registered
//     entry: "//localhost:5174", // 微应用的出口地址
//     container: "#container", // 微应用挂载的容器id
//     activeRule: "/silvia-micro", // 微应用激活路由规则
//   },
// ]);

// start();
